<style lang="scss">
.vue3-cron-div {
  .language {
    position: absolute;
    right: 32px;
    z-index: 1;
  }
  .el-tabs {
    box-shadow: none;
  }
  .tabBody {
    overflow: auto;
    .el-row {
      margin: 20px 0;
      .el-input-number {
        width: 80px;
      }
    }
  }
  .myScroller {
    &::-webkit-scrollbar {
      /*滚动条整体样式*/
      width : 5px;  /*高宽分别对应横竖滚动条的尺寸*/
      height: 5px;
    }
    &::-webkit-scrollbar-thumb {
      /*滚动条里面小方块*/
      border-radius   : 10px;
      background-color: skyblue;
      background-image: -webkit-linear-gradient(
          45deg,
          rgba(255, 255, 255, 0.2) 25%,
          transparent 25%,
          transparent 50%,
          rgba(255, 255, 255, 0.2) 50%,
          rgba(255, 255, 255, 0.2) 75%,
          transparent 75%,
          transparent
      );
    }
    &::-webkit-scrollbar-track {
      /*滚动条里面轨道*/
      box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2);
      background   : #ededed;
      border-radius: 10px;
    }
  }
  .bottom {
    width: 100%;
    margin-top: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .value {
      float: left;
      font-size: 14px;
      vertical-align: middle;
      span:nth-child(1) {
        color: red
      }
    }
  }
}
</style>
<template>
  <div class="vue3-cron-div">
    <el-tabs type="border-card">
      <el-tab-pane>
        <template #label>
          <span><i class="el-icon-date"></i> {{ state.text.Month.name }}</span>
        </template>
        <div class="tabBody myScroller" :style="{'max-height': maxHeight}">
          <el-row>
            <el-radio v-model="state.month.cronEvery" label="1">{{
              state.text.Month.every
            }}</el-radio>
          </el-row>
          <el-row>
            <el-radio v-model="state.month.cronEvery" label="2"
              >{{ state.text.Month.interval[0] }}
              <el-input-number
                v-model="state.month.incrementIncrement"
                controls-position="right"
                :min="1"
                :max="12"
              ></el-input-number>
              {{ state.text.Month.interval[1] }}
              <el-input-number
                v-model="state.month.incrementStart"
                controls-position="right"
                :min="1"
                :max="12"
              ></el-input-number>
              {{ state.text.Month.interval[2] }}
            </el-radio>
          </el-row>
          <el-row>
            <el-radio class="long" v-model="state.month.cronEvery" label="3"
              >{{ state.text.Month.specific }}
              <el-select multiple v-model="state.month.specificSpecific">
                <el-option
                  v-for="(val, index) in 12"
                  :key="index"
                  :label="val"
                  :value="val"
                ></el-option>
              </el-select>
            </el-radio>
          </el-row>
          <el-row>
            <el-radio v-model="state.month.cronEvery" label="4"
              >{{ state.text.Month.cycle[0] }}
              <el-input-number
                v-model="state.month.rangeStart"
                controls-position="right"
                :min="1"
                :max="11"
              ></el-input-number>
              {{ state.text.Month.cycle[1] }}
              <el-input-number
                v-model="state.month.rangeEnd"
                controls-position="right"
                :min="2"
                :max="12"
              ></el-input-number>
              {{ state.text.Month.cycle[2] }}
            </el-radio>
          </el-row>
        </div>
      </el-tab-pane>
      <el-tab-pane>
        <template #label>
          <span><i class="el-icon-date"></i> {{ state.text.Day.name }}</span>
        </template>
        <div class="tabBody myScroller" :style="{'max-height': maxHeight}">
          <el-row>
            <el-radio v-model="state.day.cronEvery" label="1">{{
              state.text.Day.every
            }}</el-radio>
          </el-row>
          <el-row>
            <el-radio v-model="state.day.cronEvery" label="2"
              >{{ state.text.Day.intervalWeek[0] }}
              <el-input-number
                v-model="state.week.incrementIncrement"
                controls-position="right"
                :min="1"
                :max="7"
              ></el-input-number>
              {{ state.text.Day.intervalWeek[1] }}
              <el-select v-model="state.week.incrementStart">
                <el-option
                  v-for="(val, index) in 7"
                  :key="index"
                  :label="state.text.Week[val - 1]"
                  :value="val - 1"
                ></el-option>
              </el-select>
              {{ state.text.Day.intervalWeek[2] }}
            </el-radio>
          </el-row>
          <el-row>
            <el-radio v-model="state.day.cronEvery" label="3"
              >{{ state.text.Day.intervalDay[0] }}
              <el-input-number
                v-model="state.day.incrementIncrement"
                controls-position="right"
                :min="1"
                :max="31"
              ></el-input-number>
              {{ state.text.Day.intervalDay[1] }}
              <el-input-number
                v-model="state.day.incrementStart"
                controls-position="right"
                :min="1"
                :max="31"
              ></el-input-number>
              {{ state.text.Day.intervalDay[2] }}
            </el-radio>
          </el-row>
          <el-row>
            <el-radio class="long" v-model="state.day.cronEvery" label="4"
              >{{ state.text.Day.specificWeek }}
              <el-select multiple v-model="state.week.specificSpecific">
                <el-option
                  v-for="(val, index) in 7"
                  :key="index"
                  :label="state.text.Week[val - 1]"
                  :value="state.weeks[val - 1]"
                ></el-option>
              </el-select>
            </el-radio>
          </el-row>
          <el-row>
            <el-radio class="long" v-model="state.day.cronEvery" label="5"
              >{{ state.text.Day.specificDay }}
              <el-select multiple v-model="state.day.specificSpecific">
                <el-option
                  v-for="(val, index) in 31"
                  :key="index"
                  :value="val"
                  >{{ val }}</el-option
                >
              </el-select>
            </el-radio>
          </el-row>
          <el-row v-if="false">  <!-- 暂时停用不支持的配置项 -->
            <el-radio v-model="state.day.cronEvery" label="6">{{
              state.text.Day.lastDay
            }}</el-radio>
          </el-row>
          <el-row v-if="false">  <!-- 暂时停用不支持的配置项 -->
            <el-radio v-model="state.day.cronEvery" label="7">{{
              state.text.Day.lastWeekday
            }}</el-radio>
          </el-row>
          <el-row v-if="false">  <!-- 暂时停用不支持的配置项 -->
            <el-radio v-model="state.day.cronEvery" label="8"
              >{{ state.text.Day.lastWeek[0] }}
              <el-select v-model="state.day.cronLastSpecificDomDay">
                <el-option
                  v-for="(val, index) in 7"
                  :key="index"
                  :label="state.text.Week[val - 1]"
                  :value="val - 1"
                ></el-option>
              </el-select>
              {{ state.text.Day.lastWeek[1] || "" }}
            </el-radio>
          </el-row>
          <el-row v-if="false">  <!-- 暂时停用不支持的配置项 -->
            <el-radio v-model="state.day.cronEvery" label="9">
              {{ state.text.Day.beforeEndMonth[0] }}
              <el-input-number
                v-model="state.day.cronDaysBeforeEomMinus"
                controls-position="right"
                :min="1"
                :max="31"
              ></el-input-number>
            </el-radio>
          </el-row>
          <el-row v-if="false">  <!-- 暂时停用不支持的配置项 -->
            <el-radio v-model="state.day.cronEvery" label="10"
              >{{ state.text.Day.nearestWeekday[0] }}
              <el-input-number
                v-model="state.day.cronDaysNearestWeekday"
                controls-position="right"
                :min="1"
                :max="31"
              ></el-input-number>
              {{ state.text.Day.nearestWeekday[1] }}
            </el-radio>
          </el-row>
          <el-row v-if="false">  <!-- 暂时停用不支持的配置项 -->
            <el-radio v-model="state.day.cronEvery" label="11"
              >{{ state.text.Day.someWeekday[0] }}
              <el-input-number
                v-model="state.week.cronNthDayNth"
                controls-position="right"
                :min="1"
                :max="5"
              ></el-input-number>
              {{ state.text.Day.someWeekday[1] }}
              <el-select v-model="state.week.cronNthDayDay">
                <el-option
                  v-for="(val, index) in 7"
                  :key="index"
                  :label="state.text.Week[val - 1]"
                  :value="val - 1"
                ></el-option>
              </el-select>
            </el-radio>
          </el-row>
        </div>
      </el-tab-pane>
      <el-tab-pane>
        <template #label>
          <span><i class="el-icon-date"></i> {{ state.text.Hours.name }}</span>
        </template>
        <div class="tabBody myScroller" :style="{'max-height': maxHeight}">
          <el-row>
            <el-radio v-model="state.hour.cronEvery" label="1">{{
              state.text.Hours.every
            }}</el-radio>
          </el-row>
          <el-row>
            <el-radio v-model="state.hour.cronEvery" label="2"
              >{{ state.text.Hours.interval[0] }}
              <el-input-number
                v-model="state.hour.incrementIncrement"
                controls-position="right"
                :min="0"
                :max="23"
              ></el-input-number>
              {{ state.text.Hours.interval[1] }}
              <el-input-number
                v-model="state.hour.incrementStart"
                controls-position="right"
                :min="0"
                :max="23"
              ></el-input-number>
              {{ state.text.Hours.interval[2] }}
            </el-radio>
          </el-row>
          <el-row>
            <el-radio class="long" v-model="state.hour.cronEvery" label="3"
              >{{ state.text.Hours.specific }}
              <el-select multiple v-model="state.hour.specificSpecific">
                <el-option
                  v-for="(val, index) in 24"
                  :key="index"
                  :value="val - 1"
                  >{{ val - 1 }}</el-option
                >
              </el-select>
            </el-radio>
          </el-row>
          <el-row>
            <el-radio v-model="state.hour.cronEvery" label="4"
              >{{ state.text.Hours.cycle[0] }}
              <el-input-number
                controls-position="right"
                v-model="state.hour.rangeStart"
                :min="0"
                :max="22"
              ></el-input-number>
              {{ state.text.Hours.cycle[1] }}
              <el-input-number
                v-model="state.hour.rangeEnd"
                controls-position="right"
                :min="1"
                :max="23"
              ></el-input-number>
              {{ state.text.Hours.cycle[2] }}
            </el-radio>
          </el-row>
        </div>
      </el-tab-pane>
      <el-tab-pane>
        <template #label>
          <span><i class="el-icon-date"></i> {{ state.text.Minutes.name }}</span>
        </template>
        <div class="tabBody myScroller" :style="{'max-height': maxHeight}">
          <el-row>
            <el-radio v-model="state.minute.cronEvery" label="1">{{
              state.text.Minutes.every
            }}</el-radio>
          </el-row>
          <el-row>
            <el-radio v-model="state.minute.cronEvery" label="2"
              >{{ state.text.Minutes.interval[0] }}
              <el-input-number
                v-model="state.minute.incrementIncrement"
                controls-position="right"
                :min="1"
                :max="60"
              ></el-input-number>
              {{ state.text.Minutes.interval[1] }}
              <el-input-number
                v-model="state.minute.incrementStart"
                controls-position="right"
                :min="0"
                :max="59"
              ></el-input-number>
              {{ state.text.Minutes.interval[2] || "" }}
            </el-radio>
          </el-row>
          <el-row>
            <el-radio class="long" v-model="state.minute.cronEvery" label="3"
              >{{ state.text.Minutes.specific }}
              <el-select
                multiple
                v-model="state.minute.specificSpecific"
              >
                <el-option
                  v-for="(val, index) in 60"
                  :key="index"
                  :value="val - 1"
                  >{{ val - 1 }}</el-option
                >
              </el-select>
            </el-radio>
          </el-row>
          <el-row>
            <el-radio v-model="state.minute.cronEvery" label="4"
              >{{ state.text.Minutes.cycle[0] }}
              <el-input-number
                v-model="state.minute.rangeStart"
                controls-position="right"
                :min="0"
                :max="58"
              ></el-input-number>
              {{ state.text.Minutes.cycle[1] }}
              <el-input-number
                v-model="state.minute.rangeEnd"
                controls-position="right"
                :min="1"
                :max="59"
              ></el-input-number>
              {{ state.text.Minutes.cycle[2] }}
            </el-radio>
          </el-row>
        </div>
      </el-tab-pane>
      <el-tab-pane v-if="false">
        <template #label>
          <span><i class="el-icon-date"></i> {{ state.text.Seconds.name }}</span>
        </template>
        <div class="tabBody myScroller" :style="{'max-height': maxHeight}">
          <el-row>
            <el-radio v-model="state.second.cronEvery" label="1">{{
              state.text.Seconds.every
            }}</el-radio>
          </el-row>
          <el-row>
            <el-radio v-model="state.second.cronEvery" label="2"
              >{{ state.text.Seconds.interval[0] }}
              <el-input-number
                v-model="state.second.incrementIncrement"
                controls-position="right"
                :min="1"
                :max="60"
              ></el-input-number>
              {{ state.text.Seconds.interval[1] || "" }}
              <el-input-number
                v-model="state.second.incrementStart"
                controls-position="right"
                :min="0"
                :max="59"
              ></el-input-number>
              {{ state.text.Seconds.interval[2] || "" }}
            </el-radio>
          </el-row>
          <el-row>
            <el-radio class="long" v-model="state.second.cronEvery" label="3"
              >{{ state.text.Seconds.specific }}
              <el-select
                multiple
                v-model="state.second.specificSpecific"
              >
                <el-option
                  v-for="(val, index) in 60"
                  :key="index"
                  :value="val - 1"
                  >{{ val - 1 }}</el-option
                >
              </el-select>
            </el-radio>
          </el-row>
          <el-row>
            <el-radio v-model="state.second.cronEvery" label="4"
              >{{ state.text.Seconds.cycle[0] }}
              <el-input-number
                v-model="state.second.rangeStart"
                controls-position="right"
                :min="0"
                :max="58"
              ></el-input-number>
              {{ state.text.Seconds.cycle[1] || "" }}
              <el-input-number
                v-model="state.second.rangeEnd"
                controls-position="right"
                :min="1"
                :max="59"
              ></el-input-number>
              {{ state.text.Seconds.cycle[2] || "" }}
            </el-radio>
          </el-row>
        </div>
      </el-tab-pane>
    </el-tabs>
    <div class="bottom">
      <div class="value">
        <span>
          cron预览:
        </span>
        <el-tag type="danger"> 
          {{ state.cron }}
        </el-tag>
        </div>
        <div class="buttonDiv">
      <el-button text  type="primary" @click="close">{{ state.text.Close }}</el-button>
      <el-button type="primary" @click.stop="handleChange">{{ state.text.Save }}</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import Language from "./language";
import { reactive, toRefs, computed, defineComponent, watch } from "vue";
export default defineComponent({
  name: "vue3Cron",
  props: {
    cronValue: {
      type: String,
      default: '0 * * * * *',
    },
    i18n: {},
    maxHeight: {}
  },
  setup(props, { emit }) {
    const { cronValue, i18n } = toRefs(props)
    const state = reactive({
      language: i18n,
      second: {
        cronEvery: "1",
        incrementStart: 3,
        incrementIncrement: 5,
        rangeStart: 0,
        rangeEnd: 0,
        specificSpecific: [],
      },
      minute: {
        cronEvery: "1",
        incrementStart: 3,
        incrementIncrement: 5,
        rangeStart: 0,
        rangeEnd: 0,
        specificSpecific: [],
      },
      hour: {
        cronEvery: "1",
        incrementStart: 3,
        incrementIncrement: 5,
        rangeStart: 0,
        rangeEnd: 0,
        specificSpecific: [],
      },
      day: {
        cronEvery: "1",
        incrementStart: 1,
        incrementIncrement: 1,
        rangeStart: 0,
        rangeEnd: 0,
        specificSpecific: [],
        cronLastSpecificDomDay: 1,
        cronDaysBeforeEomMinus: 0,
        cronDaysNearestWeekday: 0,
      },
      week: {
        cronEvery: "1",
        incrementStart: 1,
        incrementIncrement: 1,
        specificSpecific: [],
        cronNthDayDay: 1,
        cronNthDayNth: 1,
      },
      month: {
        cronEvery: "1",
        incrementStart: 3,
        incrementIncrement: 5,
        rangeStart: 0,
        rangeEnd: 0,
        specificSpecific: [],
      },
      output: {
        second: "",
        minute: "",
        hour: "",
        day: "",
        month: "",
        Week: "",
      },
      weeks: [ 'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT' ],
      text: computed(() => Language[state.language || "cn"]),
      secondsText: computed(() => {
        let seconds = "";
        let cronEvery = state.second.cronEvery;
        switch (cronEvery.toString()) {
          case "1":
            seconds = "*";
            break;
          case "2":
            seconds =
              state.second.incrementStart +
              "/" +
              state.second.incrementIncrement;
            break;
          case "3":
            state.second.specificSpecific.map((val) => {
              seconds += val + ",";
            });
            seconds = seconds.slice(0, -1);
            break;
          case "4":
            seconds = state.second.rangeStart + "-" + state.second.rangeEnd;
            break;
        }
        return seconds;
      }),
      minutesText: computed(() => {
        let minutes = "";
        let cronEvery = state.minute.cronEvery;
        switch (cronEvery.toString()) {
          case "1":
            minutes = "*";
            break;
          case "2":
            minutes =
              state.minute.incrementStart +
              "/" +
              state.minute.incrementIncrement;
            break;
          case "3":
            state.minute.specificSpecific.map((val) => {
              minutes += val + ",";
            });
            minutes = minutes.slice(0, -1);
            break;
          case "4":
            minutes = state.minute.rangeStart + "-" + state.minute.rangeEnd;
            break;
        }
        return minutes;
      }),
      hoursText: computed(() => {
        let hours = "";
        let cronEvery = state.hour.cronEvery;
        switch (cronEvery.toString()) {
          case "1":
            hours = "*";
            break;
          case "2":
            hours =
              state.hour.incrementStart + "/" + state.hour.incrementIncrement;
            break;
          case "3":
            state.hour.specificSpecific.map((val) => {
              hours += val + ",";
            });
            hours = hours.slice(0, -1);
            break;
          case "4":
            hours = state.hour.rangeStart + "-" + state.hour.rangeEnd;
            break;
        }
        return hours;
      }),
      daysText: computed(() => {
        let days = "";
        let cronEvery = state.day.cronEvery;
        switch (cronEvery.toString()) {
          case "1":
            break;
          case "2":
          case "4":
          case "11":
            days = "*";
            break;
          case "3":
            days =
              state.day.incrementStart + "/" + state.day.incrementIncrement;
            break;
          case "5":
            state.day.specificSpecific.map((val) => {
              days += val + ",";
            });
            days = days.slice(0, -1);
            break;
          case "6":
            days = "L";
            break;
          case "7":
            days = "LW";
            break;
          case "8":
            days = state.day.cronLastSpecificDomDay + "L";
            break;
          case "9":
            days = "L-" + state.day.cronDaysBeforeEomMinus;
            break;
          case "10":
            days = state.day.cronDaysNearestWeekday + "W";
            break;
        }
        return days;
      }),
      weeksText: computed(() => {
        let weeks = "";
        let cronEvery = state.day.cronEvery;
        switch (cronEvery.toString()) {
          case "1":
          case "3":
          case "5":
            weeks = "*";
            break;
          case "2":
            weeks =
              state.week.incrementStart + "/" + state.week.incrementIncrement;
            break;
          case "4":
            state.week.specificSpecific.map((val) => {
              weeks += val + ",";
            });
            weeks = weeks.slice(0, -1);
            break;
          case "6":
          case "7":
          case "8":
          case "9":
          case "10":
            weeks = "*";
            break;
          case "11":
            weeks = state.week.cronNthDayDay + "#" + state.week.cronNthDayNth;
            break;
        }
        return weeks;
      }),
      monthsText: computed(() => {
        let months = "";
        let cronEvery = state.month.cronEvery;
        switch (cronEvery.toString()) {
          case "1":
            months = "*";
            break;
          case "2":
            months =
              state.month.incrementStart + "/" + state.month.incrementIncrement;
            break;
          case "3":
            state.month.specificSpecific.map((val) => {
              months += val + ",";
            });
            months = months.slice(0, -1);
            break;
          case "4":
            months = state.month.rangeStart + "-" + state.month.rangeEnd;
            break;
        }
        return months;
      }),
      cron: computed(() => {
        return `${state.secondsText || "*"} ${state.minutesText ||
          "*"} ${state.hoursText || "*"} ${state.daysText ||
          "*"} ${state.monthsText || "*"} ${state.weeksText ||
          "*"}`;
      }),
    });
    const getValue = () => {
      return state.cron
    }
    const close = () => {
      emit('close')
    }
    const handleChange = () => {
      emit('change', state.cron)
      close()
    }
    const rest = (data) => {
      for (let i in data) {
        if (data[i] instanceof Object) {
          this.rest(data[i]);
        } else {
          switch (typeof data[i]) {
            case "object":
              data[i] = [];
              break;
            case "string":
              data[i] = "";
              break;
          }
        }
      }
    }
    const incrementRegexp = /^(\d+)\/(\d+)$/
    const specificRegexp = /^\d+(,\d+)*$/
    const specificWeekRegexp = /^\w+(,\w+)*$/
    const rangeRegexp = /^(\d+)-(\d+)$/
    const init = () => {
      let textList = cronValue.value.split(' ')
      if (textList.length !== 6) {
        console.error('cron is invalid: ' + cronValue.value)
        return
      }

      initSecond(textList[0])
      initMinute(textList[1])
      initHour(textList[2])
      initDay(textList[3])
      initMonth(textList[4])
      initWeek(textList[5])
    }
    const initSecond = (text) => {
      // 任意
      if (text === '*') {
        state.second.cronEvery = '1'
        return
      }
      // 增量
      let increment = text.match(incrementRegexp)
      if (increment) {
        state.second.cronEvery = '2'
        state.second.incrementStart = Number(increment[1])
        state.second.incrementIncrement = Number(increment[2])
        return
      }
      // 切确
      if (specificRegexp.test(text)) {
        state.second.cronEvery = '3'
        state.second.specificSpecific = text.split(',')
        return
      }
      // 范围
      let range = text.match(rangeRegexp)
      if (range) {
        state.second.cronEvery = '4'
        state.second.rangeStart = Number(range[1])
        state.second.rangeEnd = Number(range[2])
      }
    }
    const initMinute = (text) => {
      // 任意
      if (text === '*') {
        state.minute.cronEvery = '1'
        return
      }
      // 增量
      let increment = text.match(incrementRegexp)
      if (increment) {
        state.minute.cronEvery = '2'
        state.minute.incrementStart = Number(increment[1])
        state.minute.incrementIncrement = Number(increment[2])
        return
      }
      // 切确
      if (specificRegexp.test(text)) {
        state.minute.cronEvery = '3'
        state.minute.specificSpecific = text.split(',')
        return
      }
      // 范围
      let range = text.match(rangeRegexp)
      if (range) {
        state.minute.cronEvery = '4'
        state.minute.rangeStart = Number(range[1])
        state.minute.rangeEnd = Number(range[2])
      }
    }
    const initHour = (text) => {
      // 任意
      if (text === '*') {
        state.hour.cronEvery = '1'
        return
      }
      // 增量
      let increment = text.match(incrementRegexp)
      if (increment) {
        state.hour.cronEvery = '2'
        state.hour.incrementStart = Number(increment[1])
        state.hour.incrementIncrement = Number(increment[2])
        return
      }
      // 切确
      if (specificRegexp.test(text)) {
        state.hour.cronEvery = '3'
        state.hour.specificSpecific = text.split(',')
        return
      }
      // 范围
      let range = text.match(rangeRegexp)
      if (range) {
        state.hour.cronEvery = '4'
        state.hour.rangeStart = Number(range[1])
        state.hour.rangeEnd = Number(range[2])
      }
    }
    const initDay = (text) => {
      // 任意
      if (text === '*') {
        state.day.cronEvery = '1'
        return
      }
      // 增量
      let increment = text.match(incrementRegexp)
      if (increment) {
        state.day.cronEvery = '3'
        state.day.incrementStart = Number(increment[1])
        state.day.incrementIncrement = Number(increment[2])
        return
      }
      // 切确
      if (specificRegexp.test(text)) {
        state.day.cronEvery = '5'
        state.day.specificSpecific = text.split(',')
        return
      }
    }
    const initMonth = (text) => {
      // 任意
      if (text === '*') {
        state.month.cronEvery = '1'
        return
      }
      // 增量
      let increment = text.match(incrementRegexp)
      if (increment) {
        state.month.cronEvery = '2'
        state.month.incrementStart = Number(increment[1])
        state.month.incrementIncrement = Number(increment[2])
        return
      }
      // 切确
      if (specificRegexp.test(text)) {
        state.month.cronEvery = '3'
        state.month.specificSpecific = text.split(',')
        return
      }
      // 范围
      let range = text.match(rangeRegexp)
      if (range) {
        state.month.cronEvery = '4'
        state.month.rangeStart = Number(range[1])
        state.month.rangeEnd = Number(range[2])
      }
    }
    const initWeek = (text) => {
      // 增量
      let increment = text.match(incrementRegexp)
      if (increment) {
        state.day.cronEvery = '2'
        state.week.incrementStart = Number(increment[1])
        state.week.incrementIncrement = Number(increment[2])
        return
      }
      // 切确
      if (specificWeekRegexp.test(text)) {
        state.day.cronEvery = '4'
        state.week.specificSpecific = text.split(',')
        return
      }
    }

    init()
    watch(cronValue, init)

    return {
      state,
      getValue,
      close,
      handleChange,
      rest
    }
  },
});
</script>
